package demo2;

public class Test {

    public static Animal func2(){
        return new Dog("旺旺", 5);
    }

    public static void eatting(Animal animal){
        animal.eat();
    }

    public static void main1(String[] args) {
        // 向上转型
        // animal引用了 子类对象Dog,之所以可以这样，是因为Dog是Animal的子类
        Animal animal = new Dog("旺财", 6);
        Animal animal1 = new Cat("咪咪", 9);
        eatting(animal);
        eatting(animal1);
    }

    public static void main(String[] args) {
        Animal animal = new Dog("小旺", 2);
        if(animal instanceof Dog){
            Dog dog = (Dog) animal;
            dog.bark();
        }else{
            System.out.println("animal not instanceof Cat");
        }


        // animal是否引用了Cat类型的对象
        if(animal instanceof Cat){
            Cat cat = (Cat) animal;
            cat.mew();
        }else {
            System.out.println("animal not instanceof Cat");
        }

    }
}
